package com.sunshine.homepage.controller;

import com.sunshine.homepage.doamin.commodity;
import com.sunshine.homepage.service.HomepageMerchantService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.HashMap;
import java.util.Map;

@RestController
@RequestMapping("/merchant")
public class HomepageMerchantController  {

    @Autowired
    private HomepageMerchantService homepageMerchantService;

    /**
     * 添加商品
     */
    @RequestMapping("/hello")
    public String hello(){
        return "hello sunshine";
    }

    @PostMapping("/addCommodity")
    public Map<String, Object> addCommodity(Integer id, Integer repertoryNumber, String commodityName, String productDescription,
                            String commodityBrand, String commodityCategory,
                            MultipartFile commodityPicture, Double price)
    {
        if (id != null){
            return homepageMerchantService.updateCommodity(id, commodityName, productDescription, repertoryNumber, commodityBrand, commodityCategory, commodityPicture, price);
        }
        return homepageMerchantService.addCommodity( commodityName, productDescription, repertoryNumber, commodityBrand, commodityCategory, commodityPicture, price);
    }

    @GetMapping("/deleteCommodity/{id}")
    public boolean deleteCommodity(@PathVariable("id") Integer id){
        return homepageMerchantService.deleteCommodity(id);
    }

}